﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ZWZ.Web.Codes.Comm
{
    public static class Menu
    {
        public static List<ModelBase.Comm_Menu> GetSortMenu()
        {
            List<ModelBase.Comm_Menu> datas = DBProvider.DB.Ctx.Comm_Menu.ToList();
            return GetSortMenu(datas, null, false);
        }
        public static List<ModelBase.Comm_Menu> GetSortMenu(List<ModelBase.Comm_Menu> datas, string Pid, bool ShowTag = true)
        {
            List<ModelBase.Comm_Menu> smenu = new List<ModelBase.Comm_Menu>();
            var submenu = datas.Where(i => i.PID == Pid).OrderBy(m => m.Index).ToList();
            foreach (var menu in submenu)
            {
                var ssmenu = GetSortMenu(datas, menu.ID);
                if (ShowTag)
                {
                    if (ssmenu.Count > 0)
                    {
                        menu.Text = "│" + menu.Text;
                    }
                    else
                    {
                        menu.Text = "├­­" + menu.Text;
                    }
                }
                smenu.Add(menu);
                smenu.AddRange(ssmenu);
            }
            return smenu;
        }
    }
}